package com.leo.ordermessage.producer;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

public class GlobalOrderProducer {
    public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
        DefaultMQProducer producer = new DefaultMQProducer("producer_grp_11_02");
        producer.setNamesrvAddr("localhost:9876");

        producer.start();

        /**
         * 需要创建一个单队列的Topic, 1读1写
         * mqadmin updateTopic -b localhost:10911 -n localhost:9876 -r 1 -w 1 -t tp_demo_11_01
         */
        Message message;
        for (int i = 0; i < 100; i++) {
            message = new Message("tp_demo_11_01", ("hello world" + i).getBytes());
            producer.send(message);
        }

        producer.shutdown();
    }
}
